package text5;

import javax.swing.*;
import javax.swing.border.BevelBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

class Five extends JFrame{
    public Five(){
        input();
        frame();
        this.setVisible(true);
    }
    public void frame(){
        this.setTitle("添加组件的窗口");
        this.setLocationRelativeTo(null);
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(3);
        this.pack();
    }
    public void input(){
        Box vbox = Box.createVerticalBox();
        JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        TextArea area = new TextArea(7,38);
        p1.add(area);
        JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        JLabel l1 = new JLabel("用户名");
        TextField f1 = new TextField(9);
        JLabel l2 = new JLabel("电话");
        TextField f2 = new TextField(9);
        p2.add(l1);
        p2.add(f1);
        p2.add(l2);
        p2.add(f2);
        JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER));
        TextField f3 = new TextField(15);
        JButton b1 = new JButton("显示");
        JButton b2 = new JButton("退出");
        b1.setBackground(Color.GRAY);
        b2.setBackground(Color.GRAY);
        p3.add(f3);
        p3.add(b1);
        p3.add(b2);
        vbox.add(p1);
        vbox.add(p2);
        vbox.add(p3);
        this.add(vbox);
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (f1.getText().equals("")||f2.getText().equals("")){

                }
                else {
                   area.setText("用户名: " + f1.getText() + "\n" + "电话: " + f2.getText());
                    f3.setText("你按下了“显示“按钮");
                }
            }
        });
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(1);
            }
        });
    }
}

public class Num5 {
    public static void main(String[] args) {
        Five five = new Five();
    }
}
